home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 May / Disc 2 / PCU0503CD2.iso / BitFax_BitWare / BitWarePro / Simply / fclass20.scp < prev    next >
Encoding:
Text File  |  2001-09-05  |  22.5 KB  |  885 lines

  1. //---------------------------------------------------------
  2. // ext vars
  3. // @szATCmd  - str (LPSTR)
  4. // @szCID    - str
  5. // @szDCS    - str
  6. // @szDIS    - str
  7. // @szDCC    - str
  8. // @szHNG    - str
  9. // @szNSF    - str
  10. // @lpszRespBuff - str
  11. // @lPageCnt    - long
  12. // @lPageTotal  - long
  13. // @lSizeForNSF - long
  14. // @ComIO     
  15. // @GlStr1
  16. // @GlStr2
  17. // @RespBuffer
  18. //---------------------------------------------------------
  19.  
  20.  
  21. //---------------------------------------------------------
  22. // ext functions
  23. //fSetBaudRate(DWORD lpParam, DWORD Baud, DWORD dwN1, DWORD dwN2);
  24. //fWaitResponse(DWORD lpParam, DWORD lpBuf, DWORD lTimeOut, DWORD dwN1);
  25. //fSendATCmd(DWORD lpParam, DWORD lpBuf, DWORD dwN1, DWORD dwN2);
  26. //fSendDLE_ETX(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  27. //fSleep(DWORD lTime, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  28. //fFlushRxQueue(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  29. //fFlushTxQueue(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  30. //fSendOneChar(DWORD lpParam, DWORD dwCh, DWORD dwN1, DWORD dwN2);
  31. //fWaitOneChar(DWORD lpParam, DWORD lpResultChar, DWORD lTimeOut, DWORD dwN1);
  32. //fSetDTR(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  33. //fResetDTR(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  34. //fSetRTS(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  35. //fResetRTS(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  36. //fSetMisc(DWORD lpParam, DWORD nParity, DWORD nDataBits, DWORD nStopBits);
  37. //fSetMiscMore(DWORD lpParam, DWORD bDTRDSR, DWORD bRTSCTS, DWORD bXONXOFF);
  38. //fHardFlowControl(DWORD lpParam, DWORD Type, DWORD dwN1, DWORD dwN2);
  39. //fSoftFlowControl(DWORD lpParam, DWORD Type, DWORD dwN1, DWORD dwN2);
  40. //fSkipSpaceStrStr(DWORD s1, DWORD s2, DWORD dwN1, DWORD dwN2);
  41. //fTxFirstResponseError(DWORD s1, DWORD s2, DWORD dwN1, DWORD dwN2);
  42. //
  43. //   For fHardFlowControl:
  44. //     param1 - 0000X0YY   X  - Cts flow control
  45. //                         YY : 00 - RTS DISABLE
  46. //                         YY : 01 - RTS ENABLE
  47. //                         YY : 10 - RTS HANDSHAKE
  48. //                         YY : 11 - RTS TOGGLE
  49. //   For fSoftFlowControl
  50. //         FLOWCTRL_NONE 0
  51. //         FLOWCTRL_SEND 1    
  52. //         FLOWCTRL_RECV 2
  53. //         FLOWCTRL_BOTH 4
  54. //---------------------------------------------------------
  55.  
  56. //
  57. // This is the script file for Class2.
  58. //
  59. // trace
  60. declare STRING %szStr1, %szStr2;
  61. declare STRING %szStr3, %szStr4;
  62. declare STRING %szPass1, %szPass2;
  63. declare STRING %szPass3, %szPass4;
  64. declare STRING %szMsg1;
  65. declare long   %lRes;
  66. declare long   %lTemp;
  67. declare long   %lGRes;
  68. declare long   %lMsg1;
  69. declare char   %XON;
  70. declare STRING %szNULL;
  71.  
  72. //----------------------------------------------------------------------
  73. //----------------------------------------------------------------------
  74. sub  SubSendCmdWaitResp(STRING #szCmd, STRING #szResp, long #lWaitTime)
  75. declare long %lRes;
  76. declare STRING %szCheckAT;
  77.  
  78.         %szCheckAT = "AT"
  79.         %lRes = fSkipSpaceStrStr(%szCheckAT, #szCmd)
  80.         if (%lRes = 0)
  81.            {
  82.            %lRes = 0
  83.            goto SendCmd1
  84.            }
  85.  
  86.         %lRes = fSendATCmd(@ComIO, #szCmd)
  87.         if (%lRes!=0)
  88.            {
  89.            %lRes = 101
  90.            goto SendCmd1
  91.            }
  92.  
  93.         %lRes = fWaitResponse(@ComIO, #lWaitTime)
  94.         if (%lRes != 0)
  95.            {
  96.            %lRes = 101
  97.            goto SendCmd1
  98.            }
  99.  
  100.         %lRes = fSkipSpaceStrStr(#szResp, @RespBuffer)
  101.         if (%lRes != 0)
  102.            %lRes = 0
  103.         else
  104.            %lRes = 101
  105.  
  106. :SendCmd1
  107.         %lGRes = %lRes
  108. endsub
  109.  
  110. //----------------------------------------------------------------------
  111. // For Dialing number
  112. //----------------------------------------------------------------------
  113. :TX_DIAL
  114.     fFlushRxQueue(@ComIO)
  115.     call SubSendCmdWaitResp("AT+FLO=2", "OK", 3000)
  116.     fSleep(150)
  117.     fFlushRxQueue(@ComIO)
  118.     fSendATCmd(@ComIO, @szATCmd)
  119.     fFlushRxQueue(@ComIO)
  120.     exit(0)
  121.  
  122.  
  123.  
  124. //----------------------------------------------------------------------
  125. // For TX initialization part 1
  126. //
  127. //   and for fHardFlowControl(@ComIO, 9) - CTS on / RTS on
  128. //----------------------------------------------------------------------
  129. :TX_INIT1
  130.     fHardFlowControl(@ComIO, 9)
  131.     fSoftFlowControl(@ComIO, 1)
  132.     fSetBaudRate(@ComIO, 19200)
  133.     fFlushRxQueue(@ComIO)
  134.     fFlushTxQueue(@ComIO)
  135.     @szATCmd = "ATS0=0M0E0"
  136.     fSendATCmd(@ComIO, @szATCmd)
  137.     fSleep(500)
  138.     fFlushRxQueue(@ComIO)
  139.     @szATCmd = "ATS0=0M0E0"
  140.     fSendATCmd(@ComIO, @szATCmd)
  141.     fSleep(500)
  142.     fFlushRxQueue(@ComIO)
  143.     call SubSendCmdWaitResp("ATS0=0", "OK", 3000)
  144.     fSleep(150)
  145.     call SubSendCmdWaitResp("ATE0V1&C1", "OK", 3000)
  146.     fSleep(150)
  147. //  call SubSendCmdWaitResp(@szATCmd, "OK", 3000)
  148.     exit (%lGRes)
  149.  
  150. :TX_INIT2
  151.     call SubSendCmdWaitResp("AT+FCLASS=2.0", "OK", 3000)
  152.     fSleep(150)
  153.     if (%lGRes = 0)
  154.         fSetBaudRate(@ComIO, 19200)
  155.     exit (%lGRes)
  156.  
  157. :TX_INIT3
  158.     %szStr1 = "AT+FLI="
  159.     %szStr2 = %szStr1 + @szCID
  160.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  161.     fSleep(150)
  162.     if (%lGRes!=0)
  163.         exit (%lGRes)
  164.  
  165.     %szStr1 = "AT+FCC="
  166.     %szStr2 = %szStr1 + @szDCC
  167.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  168.     fSleep(150)
  169.     if (%lGRes!=0)
  170.         exit (%lGRes)
  171.  
  172.     %szStr2 = "AT+FNR=1,1,1,0"
  173.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  174.     fSleep(150)
  175.     if (%lGRes!=0)
  176.         exit (%lGRes)
  177.  
  178.  
  179. //
  180. // You can do all kind of thing here...
  181. :TX_INIT4
  182.     exit (0)
  183.  
  184.  
  185. //----------------------------------------------------------------------
  186. // Now we go to Tx phase B - Wait for OK and send AT+FDR
  187. //
  188. // ??? I dont know whether we need to wait for FCON or not...
  189. //----------------------------------------------------------------------
  190. :TXPH_B_START
  191.     %szStr3 = "This is in TXPH_B_START"
  192.     %lRes = fPrintMsg(%szStr3)
  193.  
  194.     %lRes = fWaitResponse(@ComIO, 5000) 
  195.     if (%lRes != 0)
  196.         exit (4)
  197.  
  198.     // Check to see if any error happens. eg: No dial tone, busy...
  199.     %lRes = fTxFirstResponseError(@RespBuffer)
  200.     if (%lRes != 0)
  201.        {
  202.        exit (%lRes)
  203.        }
  204.  
  205.     // Yes, sth is the buffer, we need to compare it
  206.     %szStr3 = "OK"
  207.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  208.     if (%lRes != 0)
  209.         {
  210.         fSleep(100)
  211.         %szStr3 = "AT+FDT"
  212.         fSendATCmd(@ComIO, %szStr3)
  213.         exit (0)            // OK
  214.         }
  215.  
  216.     %szStr3 = "+FNF"
  217.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  218.     if (%lRes != 0)
  219.         {
  220.         @szNSF = @RespBuffer
  221.         goto TXPH_B_START
  222.         }
  223.  
  224.     %szStr3 = "+FCI"
  225.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  226.     if (%lRes != 0)
  227.         {
  228.         @szCID = @RespBuffer
  229.         goto TXPH_B_START
  230.         }
  231.  
  232.     %szStr3 = "+FIS"
  233.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  234.     if (%lRes != 0)
  235.         {
  236.         @szDIS = @RespBuffer
  237.         goto TXPH_B_START
  238.         }
  239.  
  240.     // The rest of them go back to start...
  241.     goto TXPH_B_START
  242.  
  243. //----------------------------------------------------------------------
  244. // Tx Wait for training - Wait for CONNECT and XON
  245. //----------------------------------------------------------------------
  246. :TXTRAIN_START
  247.     %szStr3 = "This is in TXTRAIN_START"
  248.     %lRes = fPrintMsg(%szStr3)
  249.  
  250.     %lRes = fWaitResponse(@ComIO, 20000) 
  251.     if (%lRes != 0)
  252.         exit (1)
  253.  
  254.     // Check for FDCS
  255.     %szStr3 = "FCS"
  256.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  257.     if (%lRes != 0)
  258.        {
  259.        @szDCS = @RespBuffer
  260.        }
  261.  
  262.     if (%lRes != 0)
  263.         goto TXTRAIN_START
  264.  
  265.     // Yes, sth is the buffer, we need to compare it
  266.     %szStr3 = "CONNECT"
  267.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  268.     if (%lRes != 0)
  269.         exit (0)
  270.     else
  271.         goto TXTRAIN_START
  272.  
  273.     
  274. //----------------------------------------------------------------------
  275. //----------------------------------------------------------------------
  276. :TXPH_C_START    
  277.     fSoftFlowControl(@ComIO, 1)
  278.     exit (0)
  279.  
  280.  
  281. //----------------------------------------------------------------------
  282. // TX Phase D
  283. // If last page, then send dle_eop
  284. //               else send dle_mps
  285. //----------------------------------------------------------------------
  286. :TXPH_D_START
  287.     %szStr3 = "This is in TXPH_D_START"
  288.     %lRes = fPrintMsg(%szStr3)
  289.  
  290.     fSendOneChar(@ComIO, 0)
  291.     fSendOneChar(@ComIO, 1)
  292.     fSendOneChar(@ComIO, 16)
  293.     fSendOneChar(@ComIO, 16)
  294.     fSendOneChar(@ComIO, 0)
  295.     fSendOneChar(@ComIO, 1)
  296.     fSendOneChar(@ComIO, 16)
  297.     fSendOneChar(@ComIO, 16)
  298.     fSendOneChar(@ComIO, 0)
  299.     fSendOneChar(@ComIO, 1)
  300.     fSendOneChar(@ComIO, 16)
  301.     fSendOneChar(@ComIO, 16)
  302.     fFlushRxQueue(@ComIO)
  303.     %lRes = @lPageCnt + 1
  304.     @lPageCnt = %lRes
  305.     if (@lPageCnt >= @lPageTotal)
  306.         {
  307.         fSendOneChar(@ComIO, 16)
  308.         fSendOneChar(@ComIO, 46)
  309.         }
  310.     else
  311.         {
  312.         fSendOneChar(@ComIO, 16)
  313.         fSendOneChar(@ComIO, 44)
  314.         }
  315.  
  316.  
  317. :TXPH_D0
  318.      %lRes = fWaitResponse(@ComIO, 25000)
  319.  
  320.      // NO response error (3)
  321.      if (%lRes != 0)
  322.         exit (3)
  323.  
  324.     // Check to see if get the +FHS signal... 
  325.     %szStr3 = "FHS"
  326.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  327.     if (%lRes != 0)
  328.         {
  329.         @szHNG = @RespBuffer
  330.         if (@lPageCnt >= @lPageTotal)
  331.             exit (0)
  332.         else
  333.             exit (3)
  334.         }
  335.  
  336.      %szStr3 = "OK"
  337.      %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  338.      if (%lRes = 0)
  339.         goto TXPH_D0
  340.  
  341.  
  342.     if (@lPageCnt >= @lPageTotal)
  343.         goto TXPH_D_LASTPAGE
  344.  
  345.     // Now we have more page to send.  Send AT+FDT and then wait for CONNECT
  346.     fSleep(100)
  347.     %szStr3 = "AT+FDT"
  348.     fSendATCmd(@ComIO, %szStr3)
  349.     goto TXPH_D_MOREPAGE
  350.  
  351.  
  352. :TXPH_D_LASTPAGE
  353.     %lRes = fWaitResponse(@ComIO, 20000) 
  354.     if (%lRes != 0)
  355.         exit (3)
  356.  
  357.     // Check to see if get the +FHS signal... 
  358.     %szStr3 = "FHS"
  359.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  360.     if (%lRes != 0)
  361.         {
  362.         @szHNG = @RespBuffer
  363.         exit (0)
  364.         }
  365.  
  366.     goto TXPH_D_LASTPAGE
  367.  
  368. :TXPH_D_MOREPAGE
  369.         %lRes = fWaitResponse(@ComIO, 20000) 
  370.         if (%lRes != 0)
  371.            exit (3)
  372.  
  373.         %szStr3 = "FHS"
  374.         %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  375.         if (%lRes != 0)
  376.            {
  377.            @szHNG = @RespBuffer
  378.            exit (3)
  379.            } 
  380.  
  381.         // Yes, sth is the buffer, we need to compare it
  382.         %szStr3 = "CONNECT"
  383.         %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  384.         if (%lRes != 0)
  385.            exit (1)
  386.         else
  387.            goto TXPH_D_MOREPAGE
  388.  
  389. //----------------------------------------------------------------------
  390. // TX Disconnecting the line
  391. //----------------------------------------------------------------------
  392. :ABORT1
  393. :TX_DISC1
  394.     %szStr3 = "This is in TX_DISC1"
  395.     %lRes = fPrintMsg(%szStr3)
  396.  
  397.         fFlushRxQueue(@ComIO)
  398.         fSendDLE_ETX(@ComIO)
  399.         %szStr3 = "AT"
  400.         fSendATCmd(@ComIO, %szStr3)
  401.         fSleep(500)
  402.         %szStr3 = "AT"
  403.         fSendATCmd(@ComIO, %szStr3)
  404.         fSleep(500)
  405.         fFlushRxQueue(@ComIO)
  406.         fFlushTxQueue(@ComIO)
  407.         %szStr3 = "AT+FCLASS=0"
  408.         fSendATCmd(@ComIO, %szStr3)
  409.         fSleep(1000)
  410.         fSetBaudRate(@ComIO, 2400)
  411.         fSleep(150)
  412.         %szStr3 = "ATH0"
  413.         fSendATCmd(@ComIO, %szStr3)
  414.         fSleep(200)
  415.         fFlushRxQueue(@ComIO)
  416.         fSendATCmd(@ComIO, @szATCmd)  // comes from szTxQuitString
  417.         fSleep(500)
  418.         fResetDTR(@ComIO)
  419.         fSleep(1000)
  420.         fSetDTR(@ComIO)
  421.         fSleep(500)
  422.  
  423.         %szStr3 = "ATH0"
  424.         fSendATCmd(@ComIO, %szStr3)
  425.         fSleep(300)
  426.  
  427.         fFlushRxQueue(@ComIO)
  428.         fFlushTxQueue(@ComIO)
  429.         exit (0)
  430.  
  431. :ABORT2
  432. :TX_DISC2
  433.         fFlushRxQueue(@ComIO)
  434.         fFlushTxQueue(@ComIO)
  435.         fSendATCmd(@ComIO, @szATCmd)
  436.         fSleep(1000)
  437.         fFlushRxQueue(@ComIO)
  438.         fFlushTxQueue(@ComIO)
  439.     exit (0)
  440.  
  441. :TX_DISC3
  442.         exit (0)
  443.  
  444. :TX_DISC4
  445.         exit (0)
  446.  
  447. //----------------------------------------------------------------------
  448. // The following are for RX fax
  449. //----------------------------------------------------------------------
  450. //----------------------------------------------------------------------
  451. //  For HardFlowControl - use 11 means CTS on/RTS toggle.
  452. //----------------------------------------------------------------------
  453. :RX_INIT1
  454.     fHardFlowControl(@ComIO, 11)
  455.     fSetBaudRate(@ComIO, 19200)
  456.     fFlushRxQueue(@ComIO)
  457.     fFlushTxQueue(@ComIO)
  458.     @szATCmd = "ATS0=0M0E0"
  459.     fSendATCmd(@ComIO, @szATCmd)
  460.     fSleep(500)
  461.     fFlushRxQueue(@ComIO)
  462.     @szATCmd = "ATS0=0M0E0"
  463.     fSendATCmd(@ComIO, @szATCmd)
  464.     fSleep(500)
  465.     fFlushRxQueue(@ComIO)
  466.     call SubSendCmdWaitResp("ATS0=0", "OK", 3000)
  467.     fSleep(150)
  468.     call SubSendCmdWaitResp("AT&FE0V1&C1&D2", "OK", 3000)
  469.     fSleep(150)
  470.     exit (%lGRes)
  471.  
  472. :RX_INIT2
  473.     call SubSendCmdWaitResp("AT+FCLASS=2.0", "OK", 3000)
  474.     fSleep(150)
  475.     if (%lGRes = 0)
  476.         fSetBaudRate(@ComIO, 19200)
  477.     exit (%lGRes)
  478.  
  479. :RX_INIT3
  480.     %szStr1 = "AT+FLI="
  481.     %szStr2 = %szStr1 + @szCID
  482.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  483.     fSleep(150)
  484.     if (%lGRes!=0)
  485.         exit (%lGRes)
  486.  
  487.     %szStr1 = "AT+FCC="
  488.     %szStr2 = %szStr1 + @szDCC
  489.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  490.     fSleep(150)
  491.     if (%lGRes!=0)
  492.         exit (%lGRes)
  493.  
  494. //
  495. //    %szStr2 = "AT+FAA=0"
  496. //    call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  497. //    if (%lGRes!=0)
  498. //        exit (%lGRes)
  499. //
  500.  
  501.     %szStr2 = "AT+FNR=1,1,1,0"
  502.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  503.     fSleep(150)
  504.     if (%lGRes!=0)
  505.         exit (%lGRes)
  506.  
  507.     %szStr2 = "AT+FCR=1"
  508.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  509.     fSleep(150)
  510.     if (%lGRes!=0)
  511.         exit (%lGRes)
  512.  
  513. :RX_INIT4
  514.     exit (0)
  515.  
  516.  
  517. //----------------------------------------------------------------------
  518. // RX_WAITCALL
  519. //
  520. // Wait for 3 seconds for RING signal
  521. //----------------------------------------------------------------------
  522. :RX_WAITCALL
  523.     %szStr3 = "This is in RX_WAITCALL (C2)"
  524.     %lRes = fPrintMsg(%szStr3)
  525.  
  526.         fFlushRxQueue(@ComIO)
  527.         fFlushTxQueue(@ComIO)
  528.         %lRes = fWaitResponse(@ComIO, 3000) 
  529.         if (%lRes != 0)
  530.             exit (%lRes)
  531.  
  532.         // Something is in the buffer, check if this is RING signal
  533.         %szStr3 = "RING"
  534.         %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  535.         if (%lRes != 0)
  536.            exit (0)
  537.         else
  538.            exit (1)
  539.  
  540.  
  541. //----------------------------------------------------------------------
  542. // RX_ANSWERCALL
  543. //----------------------------------------------------------------------
  544. :RX_ANSWERCALL
  545.     %szStr3 = "This is in RX_ANSWERCALL"
  546.     %lRes = fPrintMsg(%szStr3)
  547.  
  548.         fFlushRxQueue(@ComIO)
  549.         fFlushTxQueue(@ComIO)
  550.  
  551.             call SubSendCmdWaitResp("AT+FCLASS=2.0", "OK", 3000)
  552.             fSleep(150)
  553.             if (%lGRes = 0)
  554.             fSetBaudRate(@ComIO, 19200)
  555.  
  556.         fFlushRxQueue(@ComIO)
  557.         @szATCmd = "ATA"
  558.         fSendATCmd(@ComIO, @szATCmd)
  559.             exit (0)
  560.  
  561. //----------------------------------------------------------------------
  562. // RX_PH_B_START
  563. //----------------------------------------------------------------------
  564. :RXPH_B_START
  565.     %szStr3 = "This is in RXPH_B_START"
  566.     %lRes = fPrintMsg(%szStr3)
  567.  
  568.     %lRes = fWaitResponse(@ComIO, 30000) 
  569.     if (%lRes != 0)
  570.         exit (1)
  571.  
  572.     // Check to see if any error happens. eg: No dial tone, busy...
  573.     %lRes = fTxFirstResponseError(@RespBuffer)
  574.     if (%lRes != 0)
  575.        {
  576.        exit (%lRes)
  577.        }
  578.  
  579.     // Yes, sth is the buffer, we need to compare it
  580.     %szStr3 = "OK"
  581.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  582.     if (%lRes != 0)
  583.         {
  584.         fSleep(100)
  585.         %szStr3 = "AT+FDR"
  586.         fSendATCmd(@ComIO, %szStr3)
  587.         exit (0)            // OK
  588.         }
  589.  
  590.     %szStr3 = "+FNS"
  591.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  592.     if (%lRes != 0)
  593.         {
  594.         @szNSF = @RespBuffer
  595.         goto RXPH_B_START
  596.         }
  597.  
  598.     %szStr3 = "+FTI"
  599.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  600.     if (%lRes != 0)
  601.         {
  602.         @szCID = @RespBuffer
  603.         goto RXPH_B_START
  604.         }
  605.  
  606.     %szStr3 = "+FCS"
  607.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  608.     if (%lRes != 0)
  609.         {
  610.         @szDCS = @RespBuffer
  611.         goto RXPH_B_START
  612.         }
  613.  
  614.     // The rest of them go back to start...
  615.     goto RXPH_B_START
  616.  
  617.  
  618.  
  619. //----------------------------------------------------------------------
  620. // Rx Wait for training - Wait for CONNECT and XON
  621. //----------------------------------------------------------------------
  622. :RXTRAIN_START
  623.     %szStr3 = "This is in RXTRAIN_START"
  624.     %lRes = fPrintMsg(%szStr3)
  625.  
  626.  
  627.     %lRes = fWaitResponse(@ComIO, 20000) 
  628.     if (%lRes != 0)
  629.         exit (1)
  630.  
  631.     // Check for FDCS
  632.     %szStr3 = "FCS"
  633.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  634.     if (%lRes != 0)
  635.        {
  636.        @szDCS = @RespBuffer
  637.        }
  638.  
  639.     if (%lRes != 0)
  640.         goto RXTRAIN_START
  641.  
  642.     // Yes, sth is the buffer, we need to compare it
  643.     %szStr3 = "CONNECT"
  644.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  645.     if (%lRes != 0)
  646.         exit (0)
  647.     else
  648.         goto RXTRAIN_START
  649.  
  650.  
  651.  
  652. //----------------------------------------------------------------------
  653. // RX Phase D
  654. //
  655. // exit (3) - error
  656. //      (0) - No more page to receive
  657. //      (1) - more page to receive - go to phase C
  658. //      (2) - more page to receive - BUT go to phase B
  659. //----------------------------------------------------------------------
  660. :RXPH_D_START
  661.     %szStr3 = "This is in RXPH_D_START"
  662.     %lRes = fPrintMsg(%szStr3)
  663.  
  664.  
  665.      %lTemp = 0
  666.      %lRes = @lPageTotal + 1
  667.      @lPageTotal = %lRes
  668.  
  669.      %lRes = @lPageCnt + 1
  670.      @lPageCnt = %lRes
  671.  
  672.  
  673. :RXPH_D0
  674.      %lRes = fWaitResponse(@ComIO, 25000)
  675.  
  676.      // NO response error (3)
  677.      if (%lRes != 0)
  678.         exit (3)
  679.  
  680.      %szStr3 = "FET:0"
  681.      %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  682.      if (%lRes != 0)
  683.     %lTemp = 1
  684.  
  685.      if (%lRes != 0)
  686.         goto RXPH_D1
  687.  
  688.  
  689.      %szStr3 = "FET:2"
  690.      %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  691.      if (%lRes != 0)
  692.         goto RXPH_D1
  693.  
  694.      %szStr3 = "ERROR"
  695.      %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  696.      if (%lRes != 0)
  697.         exit (3)
  698.  
  699.      %szStr3 = "FHS"
  700.      %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  701.      if (%lRes != 0)
  702.         {
  703.             @szHNG = @RespBuffer
  704.         exit (3)
  705.         }
  706.  
  707.      goto RXPH_D0
  708.  
  709. :RXPH_D1
  710.     %szStr3 = "This is in RXPH_D1_111"
  711.     %lRes = fPrintMsg(%szStr3)
  712.  
  713.     %lRes = fWaitResponse(@ComIO, 20000) 
  714.     if (%lRes != 0)
  715.         exit (3)
  716.  
  717.     // Check to see if get the +FHS signal...
  718.     %szStr3 = "FHS"
  719.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  720.     if (%lRes != 0)
  721.         {
  722.         @szHNG = @RespBuffer
  723.         exit (0)
  724.         }
  725.  
  726.     %szStr3 = "OK"
  727.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  728.     if (%lRes != 0)
  729.         goto RXPH_D2
  730.     goto RXPH_D1
  731.  
  732. //
  733. // Send AT+FDT and wait for connect
  734. //
  735. :RXPH_D2
  736.     %szStr3 = "This is in RXPH_D2_111"
  737.     %lRes = fPrintMsg(%szStr3)
  738.  
  739.     fSleep(100)
  740.     %szStr3 = "AT+FDR"
  741.     fSendATCmd(@ComIO, %szStr3)
  742.  
  743. :RXPH_D3
  744.     %lRes = fWaitResponse(@ComIO, 20000) 
  745.     if (%lRes != 0)
  746.        exit (3)
  747.  
  748.     // Yes, sth is the buffer, we need to compare it.
  749.     %szStr3 = "CONNECT"
  750.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  751.     if (%lRes != 0)
  752.        exit (1)            // more page to receive - go to phase C
  753.  
  754.     %szStr3 = "FHS"
  755.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  756.     if (%lRes != 0)
  757.            {
  758.            @szHNG = @RespBuffer
  759.            exit (0)
  760.            }
  761.  
  762.     %szStr3 = "OK"
  763.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  764.     if (%lRes != 0)
  765.        exit (0)
  766.  
  767.     %szStr3 = "ERROR"
  768.     %lRes = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  769.     if (%lRes != 0)
  770.        exit (3)
  771.  
  772.  
  773. //----------------------------------------------------------------------
  774. //
  775. //----------------------------------------------------------------------
  776. :RX_DISC1
  777.     %szStr3 = "This is in RX_DISC1"
  778.     %lRes = fPrintMsg(%szStr3)
  779.  
  780.         fFlushRxQueue(@ComIO)
  781.         fSendDLE_ETX(@ComIO)
  782.     fSleep(300)
  783.  
  784.     fSendOneChar(@ComIO, 43)
  785.     fSendOneChar(@ComIO, 43)
  786.     fSendOneChar(@ComIO, 43)
  787.     fSleep(400)
  788.  
  789.         %szStr3 = "AT"
  790.         fSendATCmd(@ComIO, %szStr3)
  791.         fSleep(300)
  792.         %szStr3 = "AT"
  793.         fSendATCmd(@ComIO, %szStr3)
  794.         fSleep(300)
  795.         fFlushRxQueue(@ComIO)
  796.         fFlushTxQueue(@ComIO)
  797.         %szStr3 = "AT+FCLASS=0"
  798.         fSendATCmd(@ComIO, %szStr3)
  799.         fSleep(1000)
  800.         fSetBaudRate(@ComIO, 2400)
  801.         fSleep(150)
  802.         %szStr3 = "ATH0"
  803.         fSendATCmd(@ComIO, %szStr3)
  804.         fSleep(500)
  805.         fFlushRxQueue(@ComIO)
  806.         fSendATCmd(@ComIO, @szATCmd)  // comes from szTxQuitString
  807.         fSleep(500)
  808.         fResetDTR(@ComIO)
  809.         fSleep(1000)
  810.         fSetDTR(@ComIO)
  811.         fSleep(500)
  812.  
  813.         fFlushRxQueue(@ComIO)
  814.         fFlushTxQueue(@ComIO)
  815.  
  816.         %szStr3 = "ATH0"
  817.         fSendATCmd(@ComIO, %szStr3)
  818.         fSleep(500)
  819.  
  820.         fFlushRxQueue(@ComIO)
  821.         fFlushTxQueue(@ComIO)
  822.         exit (0)
  823.  
  824. :RX_DISC2
  825.         fFlushRxQueue(@ComIO)
  826.         fFlushTxQueue(@ComIO)
  827.         fSendATCmd(@ComIO, @szATCmd)
  828.         fSleep(500)
  829.         fFlushRxQueue(@ComIO)
  830.         fFlushTxQueue(@ComIO)
  831.     exit (0)
  832.  
  833. :RX_DISC3
  834.     exit (0)
  835.  
  836. :RX_DISC4
  837.     exit (0)
  838.  
  839.  
  840. //----------------------------------------------------------------------
  841. //----------------------------------------------------------------------
  842. :TAPIRX_INIT1
  843.     fHardFlowControl(@ComIO, 9)
  844.     fSoftFlowControl(@ComIO, 0)
  845.     fSetBaudRate(@ComIO, 19200)
  846.     fFlushRxQueue(@ComIO)
  847.     fFlushTxQueue(@ComIO)
  848.  
  849.     call SubSendCmdWaitResp("AT", "OK", 1000)
  850.     call SubSendCmdWaitResp("AT", "OK", 1000)
  851.     fSleep(200)
  852.     fFlushRxQueue(@ComIO)
  853.     call SubSendCmdWaitResp("AT+FCLASS=2.0", "OK", 3000)
  854.     fSleep(200)
  855.     fSetBaudRate(@ComIO, 19200)
  856.  
  857.     %szStr1 = "AT+FLI="
  858.     %szStr2 = %szStr1 + @szCID
  859.     fFlushRxQueue(@ComIO)
  860.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  861.     fSleep(150)
  862.  
  863.     %szStr1 = "AT+FCC="
  864.     %szStr2 = %szStr1 + @szDCC
  865.     fFlushRxQueue(@ComIO)
  866.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  867.     fSleep(150)
  868.  
  869.     %szStr2 = "AT+FNR=1,1,1,0"
  870.     fFlushRxQueue(@ComIO)
  871.     call SubSendCmdWaitResp(%szStr2, "OK", 3000)
  872.     fSleep(150)
  873.  
  874.     fFlushRxQueue(@ComIO)
  875.     @szATCmd = "ATA"
  876.     fSendATCmd(@ComIO, @szATCmd)
  877.     exit (0)
  878.  
  879. :TAPIRX_INIT2
  880.     exit (0)
  881.  
  882. :TAPIRX_INIT3
  883.     exit (0)
  884.  
  885.